home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
forth
/
amiga
/
amigaker.arc
/
12.parsing
< prev
next >
Wrap
Text File
|
1987-12-30
|
6KB
|
158 lines
;
; 12.parsing
;
; Deals with input and stream processing.
;
* skip (s addr len char -- addr' len' ) Skips over char, while
; it is found. Returns the remaining length and the address.
dc.w -1
dc.l link3
link3 set *-4
dc.b $84,'ski',$80!'p'
cnop 0,2
_skip dc.l *+4
movem.l (sp)+,d0-d1/a0 ;d0=char,d1=len,a0=adr
ori #%00100,ccr ;set z to indicate a match
bra.s 2$ ;enter loop at end, to
1$ cmp.b (a0)+,d0 ; allow for 0 length
2$ dbne d1,1$ ;
addq.w #1,d1 ;adjust count
beq.s 3$ ; and if it's 0,adr is correct
subq.l #1,a0 ; else adjust address
3$ move.l a0,-(sp)
move.l d1,-(sp)
jmp (a3)
* scan (s addr len char -- addr' len' ) Search for char in the
; string. Leave address of the match and the remaining length.
dc.w -1
dc.l link3
link3 set *-4
dc.b $84,'sca',$80!'n'
cnop 0,2
_scan dc.l *+4
movem.l (sp)+,d0-d1/a0
andi #%11011,ccr ;clr z to indicate no match
bra.s 2$
1$ cmp.b (a0)+,d0
2$ dbeq d1,1$
addq.w #1,d1
beq.s 3$
subq.l #1,a0
3$ move.l a0,-(sp)
move.l d1,-(sp)
jmp (a3)
* /string (s addr len n -- addr' len' ) Index into string by n
dc.w -1
dc.l link3
link3 set *-4
dc.b $87,'/strin',$80!'g'
cnop 0,2
_slash_string dc.l nest
dc.l _over,_min,_rot,_over,_plus
dc.l _minus_rot,_minus,_exit
* place (s addr len to -- ) copy the string to 'to' and place
; the length byte in front of it. ( requires len+1 storage space )
dc.w -1
dc.l link0
link0 set *-4
dc.b $85,'plac',$80!'e'
cnop 0,2
_place dc.l nest
dc.l _3dup,_1_plus,_swap,_move,_c_store
dc.l _drop,_exit
* (source) (s -- addr len ) Returns the string to be scanned. The
; default for source.
dc.w -1
dc.l link0
link0 set *-4
dc.b $88,'(source',$80!')'
cnop 0,2
_nest_source dc.l nest
dc.l _loading,_fetch
dc.l _question_branch,1$
dc.l _lb,_fetch,_4_plus,_count,_branch,2$
1$ dc.l _tib,_number_tib,_fetch
2$ dc.l _exit
* source The deferred source.
dc.w -1
dc.l link3
link3 set *-4
dc.b $86,'sourc',$80!'e'
cnop 0,2
_source dc.l dodefer,_nest_source
* parse-word (s char -- addr len ) Skip leading char's, then scan
; for the next char, return the enclosed string. Updates '>in'
dc.w -1
dc.l link0
link0 set *-4
dc.b $8a,'parse-wor',$80!'d'
cnop 0,2
_parse_word dc.l nest
dc.l _to_r,_source,_tuck,_to_in,_fetch
dc.l _slash_string,_r_fetch,_skip,_over
dc.l _swap,_r_from,_scan,_to_r,_over
dc.l _minus,_rot,_r_from,_dup,_0_notequal
dc.l _plus,_minus,_to_in,_store,_exit
* parse (s char -- addr len ) Scan the input stream until char
; is found. Updates '>in'
dc.w -1
dc.l link0
link0 set *-4
dc.b $85,'pars',$80!'e'
cnop 0,2
_parse dc.l nest
dc.l _to_r,_source,_to_in,_fetch,_slash_string
dc.l _over,_swap,_r_from,_scan
dc.l _to_r,_over,_minus,_dup,_r_from
dc.l _0_notequal,_minus,_to_in,_plus_store,_exit
* 'word (s -- addr ) Leaves the address where words are put.
dc.w -1
dc.l link0
link0 set *-4
dc.b $85,$27,'wor',$80!'d'
cnop 0,2
_tick_word dc.l nest
dc.l _here,_exit
* word (s char -- addr ) Parse the input stream for char and
; return a count delimited string at here. NOTE: there is alway a NULL
; following it.
dc.w -1
dc.l link3
link3 set *-4
dc.b $84,'wor',$80!'d'
cnop 0,2
_word dc.l nest
dc.l _parse_word,_tick_word,_place
dc.l _tick_word,_dup,_count,_plus
dc.l _0,_swap,_c_store,_exit
* .( (s -- ) Type the following string on the terminal.
dc.w -1
dc.l link2
link2 set *-4
dc.b $82!immediate,'.',$80!'('
cnop 0,2
_dot_paren dc.l nest
dc.l _nest_lit,')',_parse,_type,_exit
* ( (s -- ) skip the comment enclosed by ( ) combination.
dc.w -1
dc.l link0
link0 set *-4
dc.b $81!immediate,$80!'('
cnop 0,2
_paren dc.l nest
dc.l _nest_lit,')',_parse,_2drop,_exit